﻿Imports System.Collections.Specialized
Imports System.Configuration

Friend Module Module1
    Public _connString As String = "Data Source=" & Application.StartupPath & GetSecureConnectionString()
    Public username As String

    Private Function GetSecureConnectionString() As String
        Dim secureSettings As NameValueCollection = TryCast(ConfigurationManager.GetSection("secureAppSettings"), NameValueCollection)
        Try
            Dim encryptedString = secureSettings("EncryptedConnString")
            Return SecurityHelper.DecryptString(encryptedString)
        Catch
            Return String.Empty
        End Try
    End Function

    Public Sub OpenChildForm(Of T As {Form, New})()
        Dim existingForm = 主窗体.MdiChildren.OfType(Of T)().FirstOrDefault()
        If existingForm IsNot Nothing Then
            existingForm.Activate() ' 激活已有实例 
        Else
            Dim newForm As New T()
            newForm.MdiParent = 主窗体
            newForm.WindowState = FormWindowState.Normal
            newForm.Show()
        End If
    End Sub


    '方法用于添加子窗体到指定的 TableLayoutPanel 中 
    Sub AddChildFormToTableLayoutPanel(parentPanel As TableLayoutPanel, childForm As Form, column As Integer, row As Integer)
        childForm.TopLevel = False
        parentPanel.Controls.Add(childForm, column, row)
        childForm.FormBorderStyle = FormBorderStyle.None
        childForm.Dock = DockStyle.Fill
        childForm.Visible = True
    End Sub

    Sub ClearCellContent(ByVal columnIndex As Integer, ByVal rowIndex As Integer)
        ' 1. 获取目标单元格控件
        Dim targetControl As Control = 主窗体.TableLayoutPanel1.GetControlFromPosition(columnIndex, rowIndex)

        If targetControl IsNot Nothing Then
            主窗体.TableLayoutPanel1.Controls.Remove(targetControl)

        End If
    End Sub

End Module